import sys
import os
from main2 import test_main


def print_results(query_name, base_name, result, output_path):
    fp = open(output_path + '/RESULT.txt', 'a+')
    print(f'{query_name} ', f'{base_name} ', f'{result[0]} ', f'{result[1]} '
                                                              f'{result[2]} ', f'{result[3]}', file=fp)
    fp.close()


def find_images_in_folder(folder_path, image_extensions=('.jpg', '.tif', '.png')):
    """
    在指定文件夹内查找所有图像文件。

    :param folder_path: 要搜索的文件夹路径
    :param image_extensions: 要查找的图像文件扩展名列表
    :return: 图像文件的完整路径列表
    """
    image_files = []
    for root, dirs, files in os.walk(folder_path):
        for file in files:
            if any(file.lower().endswith(ext) for ext in image_extensions):
                image_files.append(os.path.join(root, file))
    return image_files


def test(input_path, out_path):
    base_folder = input_path + '/base_map'
    test_folder = input_path + '/test_image'
    base_path = find_images_in_folder(base_folder)
    test_path = find_images_in_folder(test_folder)
    for i in range(len(test_folder)):
        print_results(os.path.basename(test_path[i]), os.path.basename(base_path[i]), [0, 0, 500, 500], out_path)


if __name__ == "__main__":
    param1 = sys.argv[1]
    param2 = sys.argv[2]
    # param1 = r'E:\satLocate'
    # param2 = r'D:\python_program\2024\sat-geo-loc'
    test_main(param1, param2)
    test(param1, param2)
